home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / lisp / packages / uncompress.el < prev    next >
Encoding:
Text File  |  1995-01-31  |  2.1 KB  |  58 lines

  1. ;;; uncompress.el --- auto-decompression hook for visiting .Z files
  2. ;; Keywords: unix extensions
  3.  
  4.  
  5. ;; ============================================================
  6. ;; NOTE: crypt.el is a much more complete version of this hack.
  7. ;; ============================================================
  8.  
  9.  
  10.  
  11. ;; When we are about to make a backup file,
  12. ;; uncompress the file we visited
  13. ;; so that making the backup can work properly.
  14. ;; This is used as a write-file-hook.
  15.  
  16. (defun uncompress-backup-file ()
  17.   (and buffer-file-name make-backup-files (not buffer-backed-up)
  18.        (not (file-exists-p buffer-file-name))
  19.        (call-process "uncompress" nil nil nil buffer-file-name))
  20.   nil)
  21.  
  22. (or (assoc "\\.Z$" auto-mode-alist)
  23.     (setq auto-mode-alist
  24.       (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
  25.  
  26. (defun uncompress-while-visiting ()
  27.   "Temporary \"major mode\" used for .Z files, to uncompress the contents.
  28. It then selects a major mode from the uncompressed file name and contents."
  29.   (if (and (not (null buffer-file-name))
  30.        (string-match "\\.Z$" buffer-file-name))
  31.       (set-visited-file-name
  32.        (substring buffer-file-name 0 (match-beginning 0))))
  33.   (message "Uncompressing...")
  34.   (let ((buffer-read-only nil))
  35.     (shell-command-on-region (point-min) (point-max) "uncompress" t))
  36.   (message "Uncompressing...done")
  37.   (set-buffer-modified-p nil)
  38.   (make-local-variable 'write-file-hooks)
  39.   (or (memq 'uncompress-backup-file write-file-hooks)
  40.       (setq write-file-hooks (cons 'uncompress-backup-file write-file-hooks)))
  41.   (normal-mode))
  42.  
  43. (or (memq 'find-compressed-version find-file-not-found-hooks)
  44.     (setq find-file-not-found-hooks
  45.       (cons 'find-compressed-version find-file-not-found-hooks)))
  46.  
  47. (defun find-compressed-version ()
  48.   "Hook to read and uncompress the compressed version of a file."
  49.   ;; Just pretend we had visited the compressed file,
  50.   ;; and uncompress-while-visiting will do the rest.
  51.   (if (file-exists-p (concat buffer-file-name ".Z"))
  52.       (progn
  53.     (setq buffer-file-name (concat buffer-file-name ".Z"))
  54.     (insert-file-contents buffer-file-name t)
  55.     (goto-char (point-min))
  56.     (setq error nil)
  57.     t)))
  58.